package com.probox.modules.controller.order;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.order.OrderPayBack;
import com.probox.common.entity.service.order.IOrderPayBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 用户退款信息Controller
 *
 * @author hds
 * @date 2021-06-07
 */
@RestController
@RequestMapping("/order/back")
public class OrderPayBackController extends BaseController
{
    @Autowired
    private IOrderPayBackService orderPayBackService;

/**
 * 查询用户退款信息列表
 */
@PreAuthorize(hasPermi = "order:back:list")
@GetMapping("/list")
        public TableDataInfo list(OrderPayBack orderPayBack)
    {
        startPage();
        List<OrderPayBack> list = orderPayBackService.queryList(orderPayBack);
        return getDataTable(list);
    }

    /**
     * 导出用户退款信息列表
     */
    @PreAuthorize(hasPermi = "order:back:export")
    @Log(title = "用户退款信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderPayBack orderPayBack) throws IOException
    {
        List<OrderPayBack> list = orderPayBackService.queryList(orderPayBack);
        ExcelUtil<OrderPayBack> util = new ExcelUtil<OrderPayBack>(OrderPayBack.class);
        util.exportExcel(response, list, "用户退款信息数据");
    }

    /**
     * 获取用户退款信息详细信息
     */
    @PreAuthorize(hasPermi = "order:back:query")
    @GetMapping(value = "/{backUid}")
    public AjaxResult getInfo(@PathVariable("backUid") Long backUid)
    {
        return AjaxResult.success(orderPayBackService.selectOrderPayBackById(backUid));
    }

    /**
     * 新增用户退款信息
     */
    @PreAuthorize(hasPermi = "order:back:add")
    @Log(title = "用户退款信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderPayBack orderPayBack)
    {
        return toAjax(orderPayBackService.insertOrderPayBack(orderPayBack));
    }

    /**
     * 修改用户退款信息
     */
    @PreAuthorize(hasPermi = "order:back:edit")
    @Log(title = "用户退款信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPayBack orderPayBack)
    {
        return toAjax(orderPayBackService.updateOrderPayBack(orderPayBack));
    }

    /**
     * 删除用户退款信息
     */
    @PreAuthorize(hasPermi = "order:back:remove")
    @Log(title = "用户退款信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{backUids}")
    public AjaxResult remove(@PathVariable Long[] backUids)
    {
        return toAjax(orderPayBackService.deleteOrderPayBackByIds(backUids));
    }
}
